home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 March: Reference Library / Dev.CD Mar 96 RL / Dev.CD Mar 96 RL.toast / Technical Documentation / develop / develop Issue 25 / develop Issue 25 code / QD3D to QTVR / ArticleCode / Source / panoDocument.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-21  |  4.2 KB  |  136 lines  |  [TEXT/MPCC]

  1. #include "QD3DtoQTVR.h"
  2. #include "extern.h"
  3. #include "document.h"
  4. #include "context.h"
  5. #include "camera.h"
  6. #include "lights.h"
  7.  
  8. DocumentPtr MyNewDocument()
  9. {
  10.     DocumentPtr             theDocument;
  11.     CWindowPtr                theWindow;
  12.     Rect                    theRect = { 0, 0, 16, 16 };
  13.     TQ3Param2D                uvValues = {-1.0, -1.0};
  14.     TQ3DrawContextObject    theDrawContext ;
  15.     TQ3AttributeSet            viewSet;
  16.     Rect                    myBounds = kMyBoundsPanoRect;
  17.     Rect                    bigRect = kMyBoundsBigRect;
  18.     TQ3ColorRGB                clearColor = kMyClearColor;
  19.     TQ3CameraObject            camera = NULL ;
  20.     RGBColor                blackColor = kMyBlackColor;
  21.     RGBColor                whiteColor = kMyWhiteColor;
  22.         
  23.     // create the document record
  24.     theDocument = (DocumentPtr )NewPtrClear(sizeof(DocumentRecord));
  25.     
  26.     // create the window to display the rendering and add referneces to the document
  27.     theWindow = (CWindowPtr)NewCWindow(0L,&myBounds,"\pRendering Window",true,documentProc,(WindowPtr)-1L,true,NULL);
  28.     if (theWindow == nil)
  29.         goto bail;
  30.     theDocument->theWindow = theWindow ;
  31.     SetWRefCon((WindowPtr)theWindow, (long)theDocument ) ;    
  32.         
  33.     // create and setup the offscreen buffer
  34.     // ** Notice that QuickDraw 3D prefers direct color
  35.     NewGWorld(&theDocument->drawContextOffscreen, 32, &bigRect, nil, nil, 0L );
  36.     if (theDocument->drawContextOffscreen == NULL)
  37.         goto bail;
  38.     
  39.     SetGWorld(theDocument->drawContextOffscreen,nil);
  40.     RGBBackColor(&whiteColor);
  41.     RGBForeColor(&blackColor);
  42.     EraseRect(&theDocument->drawContextOffscreen->portRect);
  43.     
  44.     // zero out the file spec
  45.     theDocument->theFileSpec.vRefNum = 0 ;
  46.     theDocument->theFileSpec.parID = 0 ;
  47.     theDocument->theFileSpec.name[0] = '\0' ;
  48.     
  49.     // Create the new PixMap draw context
  50.     theDrawContext = MyNewDrawContext( theDocument ) ;
  51.     if (theDrawContext == NULL)
  52.         goto bail;
  53.  
  54.     // Create the view and setup the view attributes    
  55.     theDocument->theView = Q3View_New();
  56.     Q3View_GetDefaultAttributeSet(theDocument->theView, &viewSet);
  57.     Q3AttributeSet_Add(viewSet, 
  58.         kQ3AttributeTypeSpecularColor, &clearColor);
  59.     Q3AttributeSet_Add(viewSet, 
  60.         kQ3AttributeTypeSurfaceUV, &clearColor);
  61.     Q3AttributeSet_Add(viewSet, 
  62.         kQ3AttributeTypeShadingUV, &clearColor);
  63.     Q3Object_Dispose(viewSet);    
  64.     Q3View_SetDrawContext(theDocument->theView, theDrawContext);
  65.     Q3Object_Dispose(theDrawContext);
  66.                             
  67.     // Initialize the model rotation and translation used for model rotation                        
  68.     Q3Matrix4x4_SetIdentity(&theDocument->modelRotation);
  69.     
  70.     // Add more model and view properties to the document record
  71.     theDocument->documentGroup = nil;
  72.     theDocument->documentGroupScale = 1.0;    
  73.     theDocument->currentInterpolation = kQ3InterpolationStylePixel;
  74.     theDocument->illuminationShader = Q3PhongIllumination_New();
  75.     
  76.     // Create the camera and add it to the view
  77.     camera = MyNewCamera( theDocument->theWindow ) ;
  78.     Q3View_SetCamera(theDocument->theView, camera );
  79.     Q3Object_Dispose(camera);
  80.     
  81.     // Add the renderer to the view
  82.     Q3View_SetRendererByType(theDocument->theView, kQ3RendererTypeInteractive);
  83.     
  84.     // Setup the window gworld
  85.     SetGWorld(theWindow,nil);
  86.     
  87.     return(theDocument);
  88.     
  89. bail:
  90.     if (theDocument->drawContextOffscreen)
  91.         DisposeGWorld(theDocument->drawContextOffscreen);
  92.  
  93.     if (theWindow)
  94.         DisposeWindow((WindowPtr) theWindow);
  95.  
  96.     if (theDocument)
  97.         DisposePtr((Ptr)theDocument);
  98.  
  99.     return( (DocumentPtr )nil );
  100. }
  101.  
  102.  
  103. void MyCloseDocument( DocumentPtr theDocument )
  104. {    
  105.     // if we are here we can assume the document has been saved (if required) and 
  106.     // that we can junk all of the data structures associated with the document
  107.  
  108.     // if it has a file associated, close it
  109.     if (theDocument->fRefNum)
  110.         FSClose(theDocument->fRefNum);
  111.  
  112.     // and we can dispose of the window
  113.     if(theDocument->theWindow)
  114.         DisposeWindow((WindowPtr)theDocument->theWindow);
  115.  
  116.     // dispose of our QuickDraw 3d view object
  117.     if(theDocument->theView)
  118.         Q3Object_Dispose(theDocument->theView);
  119.  
  120.     // if we have a group associated with the document, then delete that
  121.     if(theDocument->documentGroup)
  122.         Q3Object_Dispose(theDocument->documentGroup);
  123.  
  124.     if(theDocument->illuminationShader)
  125.         Q3Object_Dispose(theDocument->illuminationShader);
  126.     
  127.     if(theDocument->drawContextOffscreen != nil )
  128.         DisposeGWorld(theDocument->drawContextOffscreen) ;
  129.                 
  130.     // finally dispose of the storage used for the document and 
  131.     // decrement the document count
  132.     if( theDocument != nil )
  133.         DisposPtr((Ptr) theDocument);
  134. }
  135.  
  136.